package Work.Comparator;

import Work.Comparator.GeometricObject;
import Work.Comparator.Rectangle;
import Work.Comparator.Circle;

import java.util.*;

public class TestComparator {
  public static void main(String[] args) {
    GeometricObject g1 = new Rectangle(5, 5);
    GeometricObject g2 = new Circle(5);
    GeometricObject g3= new Circle(3);

    GeometricObject g =
            max(g1, g2, new GeometricObjectComparator());

    System.out.println("The area of the larger object is " +
            g.getArea());

    List<GeometricObject> geometricObjectList=new ArrayList<GeometricObject>();
    geometricObjectList.add(g1);
    geometricObjectList.add(g2);
    geometricObjectList.add(g3);


    Collections.sort(geometricObjectList,new GeometricObjectComparator());
    Collections.reverse(geometricObjectList);
    Collections.max(geometricObjectList,new GeometricObjectComparator());

    for (GeometricObject item:geometricObjectList
         ) {
      System.out.println(item.getArea());
    }
  }
  
  public static GeometricObject max(GeometricObject g1, 
      GeometricObject g2, Comparator<GeometricObject> c) {
    if (c.compare(g1, g2) > 0)
      return g1;
    else
      return g2;
  }
}